package com.example.permission.init;

import java.util.List;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.core.annotation.Order;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import com.example.permission.service.RegionService;
import com.example.platformsharedcommon.Constant;
import com.example.platformsharedcommon.entity.permission.Region;

/**
 * 项目启动初始化
 * 
 * @author Dhjie
 *
 */
@Component
@Order(value=1)
public class SimosApplicationRunner implements ApplicationRunner{
	private Logger logger=LoggerFactory.getLogger(SimosApplicationRunner.class);
	@Autowired
	private RegionService regionService;
	@Autowired
	private RedisTemplate<String, Object> redisTemplate;
	@Override
	public void run(ApplicationArguments args) throws Exception {
		logger.info("==服务启动后，初始化数据操作==");
		regionToRedis();
		
	}
	
	/**
	 * 把地区数据缓存到redis
	 */
	public void regionToRedis() {
		logger.info("把所有的地区数据缓存到redis中start");
		List<Region> listRegion = regionService.listRegion();
		redisTemplate.opsForValue().set(Constant.REGION_TO_REDIS, listRegion);
		logger.info("把所有的地区数据缓存到redis中end");
	}

}
